
package cn.imvc.app.controllers.info;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;

import cn.imvc.app.controllers.goods.GoodsControllerImpl;
import cn.imvc.app.entities.Activity;
import cn.imvc.app.models.ActivityModel;
import cn.imvc.app.models.LoggingModel;
import cn.imvc.core.DialogBean;
import cn.imvc.core.Render;
import cn.imvc.data.domain.ViewRequest;

public class ActivityControllerImpl implements ActivityController{
	static Logger logger = Logger.getLogger(ActivityControllerImpl.class);
	public Page<Activity> page;
	public ViewRequest viewRequest;
	public Activity activity;
	public int id;
	public int[] ids;
	public int theLimitMoney;
	public int theDiscountMoney;
	
	@Autowired
	ActivityModel activityModel;
	@Autowired
	LoggingModel loggingModel;
	public String search() {
		return null;
	}

	public String index() {
		if(viewRequest == null){
			viewRequest = new ViewRequest();
		}
		viewRequest.getSort().put("sort","ASC");
		page = activityModel.find(viewRequest);
		return "activity/index";
	}
	public String show() {
		return null;
	}

	public String editNew() {
		return "activity/edit";
	}

	public String create() {
		activity.setLimitMoney(theLimitMoney*100);
		activity.setDiscountMoney(theDiscountMoney*100);
		activityModel.save(activity);
		loggingModel.info(logger,"添加活动："+activity.getName());
		return Render.json(new DialogBean("200","添加成功","","closeCurrent"));
	}

	public String edit() {
		activity = activityModel.get(id);
		return "activity/edit";
	}

	public String update() {
		activity.setLimitMoney(theLimitMoney*100);
		activity.setDiscountMoney(theDiscountMoney*100);
		activityModel.update(id,activity);
		loggingModel.info(logger,"修改活动："+activity.getName());
		return Render.json(new DialogBean("200","修改成功","","closeCurrent"));
	}

	public String destroy() {
		activityModel.delete(id);
		loggingModel.info(logger,"删除活动："+id);
		return Render.json(new DialogBean("200","删除成功",""));
	}

	public String destroyBatch() {
		return null;
	}

	public ViewRequest getViewRequest() {
		return viewRequest;
	}

	public void setViewRequest(ViewRequest viewRequest) {
		this.viewRequest = viewRequest;
	}

	public Activity getActivity() {
		return activity;
	}

	public void setActivity(Activity activity) {
		this.activity = activity;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int[] getIds() {
		return ids;
	}

	public void setIds(int[] ids) {
		this.ids = ids;
	}

	public int getTheLimitMoney() {
		return theLimitMoney;
	}

	public void setTheLimitMoney(int theLimitMoney) {
		this.theLimitMoney = theLimitMoney;
	}

	public int getTheDiscountMoney() {
		return theDiscountMoney;
	}

	public void setTheDiscountMoney(int theDiscountMoney) {
		this.theDiscountMoney = theDiscountMoney;
	}



}
